{$CLEO .qa}
{$USE CLEO+}
{$USE Audio}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "Mp5"

// By ArtemQa146

const
    Render_S = 31@
    Render_R = 30@
    Render_O = 29@

    Clip_Model = 27@
    Clip_X = 26@
    Clip_Y = 25@
    Clip_Z = 24@
    Render_R2 = 23@
    Weapon_ID = 29
end


0085: Render_S = 0@ // (int)
0085: Render_R = 1@ // (int)
0085: Render_O = 2@ // (int)
0085: Clip_Model = 3@ // (int)
0085: Clip_X = 4@ // (int)
0085: Clip_Y = 5@ // (int)
0085: Clip_Z = 6@ // (int)
0085: Render_R2 = 7@ // (int)

        gosub @Visible_Weapon

            repeat
            wait 0
            if and
                not actor.Driving($PLAYER_ACTOR)
                02D8:   actor $PLAYER_ACTOR current_weapon == Weapon_ID
            then
                0A8D: 1@ = read_memory 0xB7CDD0 size 4 virtual_protect 0
                08C3: clear 1@ bit 12
                0A8C: write_memory 0xB7CDD0 size 4 value 1@ virtual_protect 0
                0E35: set_render_object_position Render_O 0 0 0
                0E35: set_render_object_position Render_R2 0 0 0

                if or
                    Actor.Animation($PLAYER_ACTOR) == "UZI_fire"
                    Actor.Animation($PLAYER_ACTOR) == "UZI_fire_poor"
                    Actor.Animation($PLAYER_ACTOR) == "UZI_crouchfire"
                then
                    if Actor.Animation($PLAYER_ACTOR) == "UZI_fire"
                    then 0613: 1@ = actor $PLAYER_ACTOR animation "UZI_fire" time
                    end
                    if Actor.Animation($PLAYER_ACTOR) == "UZI_fire_poor"
                    then 0613: 1@ = actor $PLAYER_ACTOR animation "UZI_fire_poor" time
                    end
                    if Actor.Animation($PLAYER_ACTOR) == "UZI_crouchfire"
                    then 0613: 1@ = actor $PLAYER_ACTOR animation "UZI_crouchfire" time
                    end
                        if
                            1@ <= 0.55
                        then
                            if
                                1@ >= 0.4
                            then
                                2@ = 0.395
                                0087: 4@ = 1@ // (float)
                                0063: 4@ -= 2@  // (float)
                                4@ *= -1.0

                                2@ = 0.3990
                                0087: 5@ = 1@ // (float)
                                0063: 5@ -= 2@  // (float)
                                //5@ /= 2.0
                                5@ /= 5.0

                                2@ = 0.3995
                                0087: 6@ = 1@ // (float)
                                0063: 6@ -= 2@  // (float)
                                6@ /= 4.0
                                6@ /= 10.0
                                6@ *= -1.0
                                if
                                    1@ <= 0.46
                                then
                                    0E35: set_render_object_position Render_O 4@ 5@ 6@
                                    0087: 7@ = 4@ // (float)
                                    0087: 8@ = 5@ // (float)
                                    0087: 9@ = 6@ // (float)
                                else
                                    if
                                        1@ <= 0.55
                                    then
                                        0E35: set_render_object_position Render_O 7@ 8@ 9@
                                    end
                                end
                            end
                        end
                    end

                    get_char_weapon_clip $PLAYER_ACTOR store_to 0@
                    if and
                        0@ > 0
                        not Actor.Animation($PLAYER_ACTOR) == "UZI_reload"
                        not Actor.Animation($PLAYER_ACTOR) == "UZI_crouchreload"
                    then
                        10@ = 0
                        0E31: set_render_object_visible Render_R 1
                    end

                        if or
                            Actor.Animation($PLAYER_ACTOR) == "UZI_reload"
                            Actor.Animation($PLAYER_ACTOR) == "UZI_crouchreload"
                        then
                            if Actor.Animation($PLAYER_ACTOR) == "UZI_reload"
                            then 0613: 1@ = actor $PLAYER_ACTOR animation "UZI_reload" time
                            end
                            if Actor.Animation($PLAYER_ACTOR) == "UZI_crouchreload"
                            then 0613: 1@ = actor $PLAYER_ACTOR animation "UZI_crouchreload" time
                            end
                                if and
                                    1@ <= 0.8
                                    1@ >= 0.2
                                then
                                    if and
                                        10@ == 0
                                        1@ <= 0.4
                                    then
                                        10@ = 1
                                        0E31: set_render_object_visible Render_R 0
                                        
                                        0A92: stream_custom_script "Clip.qa" Clip_Model Clip_X Clip_Y Clip_Z
                                        
                                        end
                                    end

                                    if and
                                        1@ >= 0.6
                                        1@ <= 0.8
                                    then

                                        if
                                            1@ <= 0.65
                                        then
                                            2@ = 0.595
                                            0087: 4@ = 1@ // (float)
                                            0063: 4@ -= 2@  // (float)
                                            4@ *= -1.0

                                            2@ = 0.5990
                                            0087: 5@ = 1@ // (float)
                                            0063: 5@ -= 2@  // (float)
                                            //5@ /= 2.0
                                            5@ /= 5.0

                                            2@ = 0.5995
                                            0087: 6@ = 1@ // (float)
                                            0063: 6@ -= 2@  // (float)
                                            6@ /= 4.0
                                            6@ /= 10.0
                                            6@ *= -1.0
                                        end

                                        0E35: set_render_object_position Render_O 4@ 5@ 6@
                                        0087: 1@ = 4@ // (float)
                                        0087: 2@ = 5@ // (float)
                                        0087: 3@ = 6@ // (float)
                                        0E35: set_render_object_position Render_R2 1@ 2@ 3@
                                        if
                                            10@ == 1
                                        then
                                            0E31: set_render_object_visible Render_R 1
                                            if
                                                1@ >= 0.65
                                            then
                                                10@ = 0
                                            end
                                        end
                                    end
                                end


            else
                break
            end
            until not player.Defined(0)
                0A8D: 1@ = read_memory 0xB7CDD0 size 4 virtual_protect 0
                08BD: set 1@ bit 12
                0A8C: write_memory 0xB7CDD0 size 4 value 1@ virtual_protect 0
            gosub @Hide_Weapon
            
0A93: terminate_this_custom_script



:Hide_Weapon
0E31: set_render_object_visible Render_S 0
0E31: set_render_object_visible Render_R 0
0E31: set_render_object_visible Render_R2 0
0E31: set_render_object_visible Render_O 0
return

:Visible_Weapon
0E31: set_render_object_visible Render_S 1
0E31: set_render_object_visible Render_R 1
0E31: set_render_object_visible Render_R2 1
0E31: set_render_object_visible Render_O 1
return
